<template>
	<view class="gui-padding">

		<view class="gui-margin-top gui-padding">
			<view class=""
				style="line-height: 60rpx; border:1rpx solid #ccc;border-radius: 10rpx;padding: 20rpx;box-shadow:5rpx 5rpx 5rpx #ccc ;">
				<view>订单信息：</view>

				<view>金额：{{memberData.data3.price}}</view>
				<view>编号：{{memberData.id}}</view>
				<view>详情：{{memberData.data3.name}}-{{memberData.data3.phone}}</view>
				<view>
					{{memberData.data3.city}}-{{memberData.data3.address}}
				</view>
				<view class="gui-color-gray ">OID:{{open_id}}</view>
			</view>
		</view>
		<view style="margin-top: 200rpx; text-align: center;" v-if="pay_ok==0">
			<view class="" v-if="loadtext==''">
				<button type="warn" class="gui-button" @click="pay">支付</button>
			</view>
			<view class="gui-margin-top" v-if="loadtext==''">

				<button v-if="backtype=='app'" open-type="launchApp" app-parameter="wechat"
					binderror="launchAppError">返回</button>
				<button v-else class="gui-button" @click="back()">返回</button>
			</view>
			<view v-else class="gui-color-gray gui-margin-top">
				{{loadtext}}
			</view>
		</view>
		<view v-if="pay_ok==1" class="gui-padding">
			<view class="pay_info gui-bg-red">支付成功！</view>
		</view>
		<view v-if="pay_ok==2" class="gui-padding">
			<view class="pay_info " style="background-color: #ccc;color: #333;">支付失败？</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				backtype: '',
				pay_ok: 0,
				parm: {
					name: '',
					money: 0,
					id: 0,
					text: ''
				},
				loadtext: '',
				open_id: '',
				memberData: [],
				id: 0,
				user: uni.getStorageSync("member"),
			}
		},
		onLoad(option) {
			let self = this;
			if (option.hasOwnProperty('backtype')) {
				console.log('backtype');
				this.backtype = option.backtype;
			}
			// if (option.hasOwnProperty('user_id')) {
			// 	console.log('user_id');
			// 	this.loadtext = "获取用户信息!";
			// 	this.getuser(option.user_id);
			// }
			uni.showLoading({
				title: '加载中'
			});
			this.getData();
			this.getOpenId();
			// console.log(decodeURIComponent( opt.data));
			// this.parm = JSON.parse(decodeURIComponent(opt.data));
			// console.log("parm", this.parm);

		},
		methods: {
			// getuser(id) {
			// 	this.$common.login({
			// 		"lg_id": id
			// 	}, function(res) {
			// 		success(res);
			// 	});
			// },
			getOpenId() {
				this.loadtext = "正在获取用户ID";
				let self = this;
				let openId = ''
				uni.login({
					"provider": "weixin",
					"onlyAuthorize": true, // 微信登录仅请求授权认证
					success: function(res) {
						//code值(5分钟失效)
						console.log("login——res: ", res);
						let code = res.code;
						uni.request({
							method: "POST",
							// url: "https://jf.boyaltd.cn/api/pay/wx/openid",
							url: "https://jf.lgwisdomunion.cn/api/pay/wx/openid",
							data: {
								"code": code,
							},
							success(res) {
								self.loadtext = '';
								console.log('getOpenId: ', res)
								self.open_id = res.data.openid;
							}
						})
					},
					fail: function(err) {
						console.log('login错误：', err);
					}
				});
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			pay() {
				let r = {
					"t": "memberData",
					"id": this.memberData.id,
					"write": "data5"
				};
				let self = this;
				//雀丰

				this.loadtext = "发起支付中";
				uni.request({

					// url: "https://jf.boyaltd.cn/api/pay/wx",
					url: "https://jf.lgwisdomunion.cn/api/pay/wx",
					data: {
						money: this.memberData.data3.price,
						"open_id": this.open_id,
						"body": "快递费" + this.parm.id,
						"type": "QF",
						"d": JSON.stringify(r)
					},
					method: "POST",
					success(res) {
						console.log('api/pay/wx————', res);
						self.loadtext = '';
						let data = res.data.data
						// console.log(data)
						// let orderInfo={
						//         "appid": data.appId,  // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
						//         "nonceStr": data.nonceStr, // 随机字符串
						//         "package": "Sign=WXPay",        // 固定值
						//         "partnerid": "1528843291",      // 微信支付商户号
						//         "prepayid": data.orderid, // 统一下单订单号 
						//         "timeStamp": data.timeStamp+'',        // 时间戳（单位：秒）
						//         "paySign": data.paySign ,// 签名，这里用的 MD5/RSA 签名
						// 		"signType":"MD5"
						//     }
						//console.log(orderInfo);
						// let d = {
						// 	id: self.memberData.id,
						// 	data5: data.orderid
						// }
						// self.$common.set_member_data("zq_2023", d, function(res) {

						// });

						// uni.requestPayment({
						// 	"provider": "wxpay",
						// 	// "orderInfo": orderInfo,
						// 	"timeStamp": data.timeStamp,
						// 	"nonceStr": data.nonceStr,
						// 	"package": data.package,
						// 	"signType": data.signType,
						// 	"paySign": data.paySign,
						// 	success(res) {
						// 		console.log("pay_ok", res);
						// 		self.pay_ok = 1;
						// 		uni.showToast({
						// 			title: "支付成功",
						// 			icon: "success"
						// 		})
						// 		let d = {
						// 			id: self.memberData.id,
						// 			status: "1"
						// 		};
						// 		console.log(d);
						// 		self.$common.set_member_data("zq_2023", d, function(res) {
						// 			self.pay_find(data.orderid);
						// 		});
						// 		uni.navigateTo({
						// 			url: '/pages/zhongqiu/index'
						// 		})
						// 	},
						// 	fail(e) {
						// 		console.log("pay_err", e)
						// 		self.pay_ok = 2;
						// 		uni.showToast({
						// 			title: "错误",
						// 			icon: "error"
						// 		})
						// 	}
						// })

					}
				})
			},
			pay_find(id) {
				//支付状态查询
				let self = this;
				uni.request({
					url: this.$common.apiUrl + "/pay/wx/find",
					data: {
						"id": id
					},
					method: "POST",
					success(res) {

					}
				})
			},
			getData() {
				let self = this;
				self.$boya.Request({
					url: '/api/get_member_data',
					data: {
						type: 'wy_2024',
						user: {
							id: self.user.id
						}
					}
				}, function(res) {
					uni.hideLoading();
					if (res.data) {
						self.memberData = res.data
						if (res.data.data1 == 'A') {
							// self.memberData = res.data;
							self.memberData.data3 = JSON.parse(self.memberData.data3);
						}
					}
					console.log("get_member_data", self.memberData);
				}, false)
			},

		}
	}
</script>

<style>
	.pay_info {

		margin-top: 100rpx;
		padding: 50rpx;
		text-align: center;
		font-size: 40rpx;
		color: white;
		border-radius: 10rpx;
	}
</style>